package com.example.asus.testdesign;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class OtherActivity extends AppCompatActivity {
    private Intent intent=null;
    private Bundle bunde=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_other);

        //取得Intent中的Bundle对象
        bunde=this.getIntent().getExtras();
        //取得Bundle对象中的数据
        String ans=bunde.getString("ans");
        //判断所选答案
        String sexText="";
        if(ans.equals("Bruce Wayne"))
            sexText="Correct";
        else
            sexText="Wrong";
        TextView tv1=(TextView)findViewById(R.id.text1);
        tv1.setText("Your answer is:"+sexText);
        intent=new Intent();
        bunde.putString("ans",ans);
        //将Bundle对象assign给Intent
        intent.putExtras(bunde);


        Button b1=(Button)findViewById(R.id.button_back);
        b1.setOnClickListener(new Button.OnClickListener(){
            @Override
            public void onClick(View v){
                OtherActivity.this.setResult(RESULT_OK,intent);
                OtherActivity.this.finish();
            }
        });
    }
}
